# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/22 下午4:17
 @Author  : tgy
 
"""
import struct
import socket
import threading
import os


def run(client, client_msg):
    ...
    path = client.recv(1024).encode('utf-8')
    full_path = './' + path
    if not os.path.exists(full_path):
        ...
        client.send(b'file not exist')
        client.close()
        return

    b_arr_size = struct.pack('i', os.path.getsize(path))
    client.send(b_arr_size)

    read_buf = 1024
    with open(path, mode='rb') as f:
        client.send(f.read(read_buf))

    client.close()




class Server:

    def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):
        ...
        self.address = address
        self.socket = socket.socket(family, type)
        self.socket.bind(address)
        self.socket.listen(128)

    def start(self):
        ...
        client, client_msg = self.socket.accept()

        thread = threading.Thread(target=run, args=(client, client_msg))
        thread.start()


if __name__ == '__main__':
    ...
    server = Server(('0.0.0.0', 8090))
    server.start()
